<template>
  <div class="cart py-container">
    <!--主内容-->
    <div class="checkout py-container  pay">
      <div class="checkout-tit">
        <h4 class="fl tit-txt"><span class="success-icon"></span><span class="success-info">订单提交成功，请您及时付款！订单号：{{payObj.out_trade_no}}</span>
        </h4>
        <span class="fr"><em class="sui-lead">应付金额：</em><em class="orange money">￥{{payObj.total_fee}}</em></span>
        <div class="clearfix"></div>
      </div>
      <div class="checkout-steps">
        <div class="fl weixin">微信支付</div>
        <div class="fl sao">
          <p class="red">请使用微信扫一扫。</p>
          <div class="fl code">
            <!-- <img id="qrious" src="~/assets/img/erweima.png" alt=""> -->
            <!-- <qriously value="weixin://wxpay/bizpayurl?pr=R7tnDpZ" :size="338"/> -->
            <qriously :value="payObj.code_url" :size="338"/>
            <div class="saosao">
              <p>请使用微信扫一扫</p>
              <p>扫描二维码支付</p>
            </div>
          </div>

        </div>
        <div class="clearfix"></div>
        <!-- <p><a href="pay.html" target="_blank">> 其他支付方式</a></p> -->
      </div>
    </div>
  </div>
</template>

<script>
  import orderApi from '@/api/order';

  export default {
    data() {
      return {
        //订单编号
        orderNum: '',

        //返回的包含的二维码的信息
        payObj: {},

        //定时器
        timer: '',
      }
    },
    created() {
      this.orderNum = this.$route.params.id;
    },
    mounted() {
      this.createNative();
      //每隔3秒发送请求查询
      this.timer = setInterval(() => this.getOrderStatus(),3000);
    },

    methods: {
      //生成对应的二维码
      async createNative() {
        const {data} = await orderApi.createNative(this.orderNum);
        if (data.code !== 20000) return this.$message.error(data.message);
        this.payObj = data.data;
      },

      //查询订单状态
      async getOrderStatus() {
        const {data} = await orderApi.getOrderStatus(this.orderNum);
        console.log(data);
        if (data.code === 20000) {
          //清除定时器，不让其一直发送请求进行查询
          clearInterval(this.timer);
          this.$message.success('支付成功');
          //跳转到课程页面
          await this.$router.push('/course/' + this.payObj.course_id)
        }
      },
    }
  }
</script>

<style scoped>

</style>
